package math.vectorSpace.R3.object;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Polygon;

import math.vectorSpace.R2.Point2D;
import math.vectorSpace.R3.Point3D;
import math.vectorSpace.R3.visualization.Render3D;
import math.vectorSpace.R3.Vector3D;
import math.vectorSpace.R3.visualization.RenderOrthographic;
import math.vectorSpace.R3.visualization.VisualizationProperties;

public class Tank extends MovableObject {

    public Tank(Point3D center) {
        totalPts = 26;
        v = new Vector3D[totalPts];
        this.center = center;

        // A
        v[0] = new Vector3D(-180, 100, 26.6);
        v[1] = new Vector3D(-180, 100, 8.6);
        v[2] = new Vector3D(-54.3, 100, 8.6);
        v[3] = new Vector3D(-126.3, 100, 26.6);

        // B
        v[4] = new Vector3D(-180, 100, 0);
        v[5] = new Vector3D(-144, 100, 0);
        v[6] = new Vector3D(-135.3, 100, -27);
        v[7] = new Vector3D(197, 100, -27);
        v[8] = new Vector3D(206, 100, -9);
        v[9] = new Vector3D(197, 100, 0);
        v[10] = new Vector3D(152, 100, 8.6);

        // Wheels
        v[11] = new Vector3D(-164, 90, 11);
        v[12] = new Vector3D(-130, 90, -31);
        v[13] = new Vector3D(-76, 90, -31);
        v[14] = new Vector3D(-22, 90, -31);
        v[15] = new Vector3D(31, 90, -31);
        v[16] = new Vector3D(85, 90, -31);
        v[17] = new Vector3D(139, 90, -31);
        v[18] = new Vector3D(184, 90, -22);

        // Track
        v[19] = new Vector3D(-99, 100, -54);
        v[20] = new Vector3D(-189, 100, 36);
        v[21] = new Vector3D(-207, 100, -62);
        v[22] = new Vector3D(135, 100, -54);
        v[23] = new Vector3D(197, 100, -18);
        v[24] = new Vector3D(161, 100, -54);
        v[25] = new Vector3D(197, 100, -45);

    }

    @Override
    public void draw(Render3D display, Graphics2D g,
            VisualizationProperties properties) {

        Point2D[] rendered = new Point2D[totalPts];
        for (int i = 0; i < totalPts; i++) {
            rendered[i] = display.project(center.add(v[i]));
        }
        Polygon p = new Polygon();

        // Wheels

        // Track
        g.setStroke(new BasicStroke(4.0f, BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND, 20.0f));
        g.setColor(new Color(0.7f, 0.5f, 0.2f));
        drawCubicCurve(rendered[5], rendered[20], rendered[21], rendered[19], g);
        drawSegment(rendered[19], rendered[22], g);
        drawCubicCurve(rendered[22], rendered[24], rendered[25], rendered[23], g);

        // A
        for (int i = 0; i < 4; i++) {
            addPoint(p, rendered[i]);
        }
        g.setColor(new Color(0.8f, 0.8f, 0.8f));
        g.fill(p);

        // B
        p = new Polygon();
        addPoint(p, rendered[1]);
        for (int i = 4; i < 11; i++) {
            addPoint(p, rendered[i]);
        }
        g.setColor(new Color(0.7f, 0.7f, 0.7f));
        g.fill(p);

    }
}
